<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>AJAX交互效果实现</title>
</head>
<body>
    <input type="text" name="search" id="search" placeholder="search...">
    <div id="result"></div>
    <script>
        var xhr = new XMLHttpRequest();
        xhr.open('GET', 'searchResult.json', true);
        xhr.onreadystatechange = function() {
            if (xhr.readyState === 4 && xhr.status === 200) {
                var data = JSON.parse(xhr.responseText);
                var result = document.getElementById('result');
                result.innerHTML = '';
                data.forEach(function(item) {
                    result.innerHTML += '<p>' + item.name + '</p>';
                });
            }
        };
        document.getElementById('search').addEventListener('input', function() {
            xhr.send('query=' + this.value);
        });
    </script>
</body>
</html>